$(function () {
	
menuValidator();
	
if($("#popuperrorMessage").val()==='true'){
	$('#menu_add_and_update').modal('show');
}

$("body").on("click",'a[name="show"]',function(){

	$("#menuUuidInsertDiv").prop("class","form-group hidden");
	var menuUuid=$(this).attr("id");
	var url="/menu/getMenu";
	if(!isEmpty(menuUuid)){
		var data = {
					'menuUuid' : menuUuid,
					};
		var datas=ajaxUtil(url, data, false, "","");
		if(!isEmpty(datas)){
			
			  $("#menuUuid").val(datas.data.menuUuid);
			  $("#menuName").val(datas.data.menuName);
			  $("#menuUrl").val(datas.data.menuUrl);
			  $("#menuClasstype").val(datas.data.menuClasstype);
			  var menuPuuid=datas.data.menuPuuid;
			  if(!isNaN(menuPuuid)){
	  			$("#menuPuuid1").find("option:selected").attr("selected",false);
	  			$("#menuPuuid1 option").each(function(){
	  				var id=$(this).val();
	  				if(parseInt(menuPuuid)==parseInt(id)){
	  					$(this).attr("selected", true);
	  				}
	  			});
	  			}else{
	  				$("#menuPuuid1").find("option:selected").attr("selected",false);
	  				$("#menuPuuid1 option[index='0']").attr("selected",true);
	  			}
			  
			    var RoleList=datas.data.RoleList;
				 $(".icheckbox_minimal-blue").attr("class","icheckbox_minimal-blue");
	  		     for(var i=0;i<RoleList.length;i++){
	  		    	$('input[name="roleUuids"]').each(function(){
	      				if($(this).val()==RoleList[i].roleUuid){
	      					$(this).parent().attr("class","icheckbox_minimal-blue checked");
	      					$(this).attr("checked",true);
	      				}
	      			});
	  		     }  
			$('#menu_add_and_update').modal('show');
		}else{
			$('#menu_add_and_update').modal('hide');
		}
	}
});


$("[name='cleanAll']").click(function(){
	
	if($(this).attr("type")!="reset"){
		$("#menuUuid").val("");
		$("#menuUuidInsertDiv").prop("class","form-group show");
	}
	$('input[type="checkbox"]').attr("checked",false);
    $(".icheckbox_minimal-blue").attr("class","icheckbox_minimal-blue");
    $("#empDegree1 option[index='0']").attr("selected",true);
    $("#imenuUuid").parent().attr("class","show");
    $(":text").val("");
	$("span[name='message']").text("");
	$("#errorMessageAll").remove();
	//Modal验证销毁重构
    $("#formMenu").data('bootstrapValidator').destroy();
    $('#formMenu').data('bootstrapValidator', null);
    menuValidator();
});

$("body").on("click",'.example5-3-2', function(){
	var menuUuid=$(this).attr("id");
	var menUuid=$("input[name='menUuid']").val();
	var url="/menu/delete?menuUuid="+menuUuid+"&menUuid="+menUuid;
	deleteAlert(url);
});

});

function menuValidator(){
	$("#formMenu").bootstrapValidator({
	    message: 'This value is not valid',
	    feedbackIcons: {
	        valid: 'glyphicon glyphicon-ok',
	        invalid: 'glyphicon glyphicon-remove',
	        validating: 'glyphicon glyphicon-refresh'
	    },
	    fields: {
	        menuName: {
	        	validators: {
	            	notEmpty : {
						message : '菜单名称不能为空'
					}
	            }
	        },
	        menuUuidInsert: {
	            validators: {
	                notEmpty: {
	                    message: '菜单id不能为空'
	                }
	            }
	        },
	        menuUrl: {
	            validators: {
	                notEmpty: {
	                    message: '密码不能为空'
	                }
	            }
	        },
	        menuClasstype: {
	            validators: {
	                notEmpty: {
	                    message: '菜单图标不能为空'
	                }
	            }
	        },
	    },
	    submitHandler: function (validator, form, submitButton) {
	        alert("submit");
	    }
	});
}

